<extend name="common:base" />
<block name="content">

    <form action="{:U('Order/detail')}" class="form form-horizontal" id="add-confirm" method="post">
    <div class="left-body">
        <div id="header">
            <div class="header">
                <h1 class="tit">商品详情</h1>
                <!--<p class="goback">-->
                    <!--<a class="return" onclick="self.location=document.referrer;">返回</a>-->
                    <!--&lt;!&ndash;<a class="close" href="#">关闭</a>&ndash;&gt;-->
                <!--</p>-->
                <!--<p class="more"><a class="share"></a></p>-->
            </div>
        </div>

        <!--轮播图-->
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <volist name="goodpic" id="goodpic" >
                    <div class="swiper-slide"><img src="{$goodpic['img']}"/></div>
                </volist>
            </div>
            <div class="swiper-pagination"></div>
        </div>
        <input type="hidden" name= good_ida value="{$id}" id="good_id">
        <input type="hidden" name="good_num" value="" id="good_num">
        <if condition="$is_agent eq 1 AND $agent_brand eq 1">
            <input type="hidden" name="status" value="1" class="a_type">
            <else/>
            <input type="hidden" name="status" value="0" class="a_type">
        </if>
        <input type="hidden" name="count" value="" id="count">
        <input type="hidden" name="good_spec" value="" id="good_spec">

        <input type="hidden" value="{$is_agent}" id="is_agent">
        <!--商品市场信息-->
        <div class="mer-news">
            <div class="tit-text">
                <span>休闲</span>
                {$goodsdetail['g_name']}
            </div>
            <div class="news-price-num">
                <div class="news-price">
                    <span class="tit-price"><i>¥</i><span id="price">{$goodsdetail['price']}</span></span>
                    <span class="market-price">市场价</span>
                </div>
                <!--<div class="news-num">
                    <span class="symbol reduce">-</span>
                    <span class="tit-num num" id="num0">1</span>
                    <span class="symbol plus">+</span>
                </div>-->
            </div>
            <div class="impor">
                <span class="comm">代理商品</span>
                <span class="adr">广东深圳</span>
            </div>
        </div>

        <!--拿货价-->
        <div class="pur-price">
            <if condition="$agent_brand eq 1 AND $is_agent eq 1">
                <div class="chase-price">
                    <span class="price-text">拿货价</span>
                    <span class="prcie-num"><i>¥</i><span class="dan-price">{$goodsdetail['unit_amt']}</span>/件</span>
                </div>
            </if>
            <div class="pur-demark">
                <span class="price-text">品牌</span>
                <span class="prcie-num">{$b_name}</span>
            </div>
        </div>

        <!--规格信息选择-->
        <div class="pur-price">
            <!--选择规格点击-->
            <p class="pur-chose" id="pur">
                请选择规格
            </p>
            <!--选择规格后信息-->
            <div class="selected">
                <span class="fixation">已选：</span>
                <span class="unset ">190/XXL  自由搭配</span>
            </div>
            <!--配送方式点击-->
            <!--<p class="mode-of">配送方式</p>-->
            <!--选择方式后信息-->
            <div class="has-shipped">
                <span class="fixation">配送方式:</span>
                <span class="unset ">货到付款</span>
            </div>
            <!--灰色弹出遮出层-->
            <div class="tips-window"></div>
            <!--选择规格弹出-->
            <div class="menu-show">
                <!--规格弹窗头部-->
                <div class="menu-top">
                    <div class="first-pic"><img src="{$goodsdetail['img']}"/></div>
                    <span class="wipe-out"></span>
                    <div class="spec-price">
                        <if condition="$is_agent eq 1 AND $agent_brand eq 1">
                            <span class="pro-price"><i>¥</i>
                            <span class="total_price">{$goodsdetail['unit_amt']}</span>
                            </span>
                            <else/>
                            <span class="pro-price"><i>¥</i>
                            <span class="total_price">{$goodsdetail['price']}</span>
                            </span>
                        </if>

                        <p class="repertory">库存<span id="stock">{$goodsdetail['stock']}</span>件</p>
                        <p class="spec-choose">选择规格</p>
                    </div>
                </div>
                <volist name="goodSpec" id="vo" key="k">
                    <div class="pro-size">
                        <span class="size-tit">{$vo['s_name']}</span>
                        <div class="menu-size">
                            <foreach name="vo['spec_val']" item="v" >
                                <div class="close-size">
                                    <input type="radio" name="attr_{$k}" class="spec"/>
                                    <span>{$v}</span>
                                </div>
                            </foreach>
                        </div>
                    </div>
                </volist>

                <!--<if condition="$agent_brand eq 1 AND $is_agent eq 1">-->
                    <!--<div class="pro-size">-->
                        <!--<span class="size-tit">类型</span>-->
                        <!--<div class="menu-size">-->
                            <!--<div class="close-size">-->
                                <!--<input type="radio" name="good_type" for="2" value="{$goodsdetail['batch_amt']}"/>-->
                                <!--<span>整箱</span>-->
                            <!--</div>-->
                            <!--<div class="close-size">-->
                                <!--<input type="radio" name="good_type"  for="1" value="{$goodsdetail['unit_amt']}"/>-->
                                <!--<span>单件</span>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                <!--</if>-->


                <!--数量-->
                <div class="pro-num">
                    <span class="num-tit">购物数量</span>
                    <div class="math-num">
                        <span class="symbol reduce">-</span>
                        <span class="tit-num num" id="num">1</span>
                        <span class="symbol plus">+</span>
                    </div>
                </div>
                <!--加入购物车点击-->
                <div class="spec-menu-btn">
                    <span class="jiaru">加入购物车</span>
                    <span class="ljgm" id="lima">立即购买</span>
                    <input class="visitor" type="hidden" value="{$session}">
                </div>
            </div>
            <!--加入购物车成功图片弹窗-->
            <!--<div class="join-car"></div>-->
            <!--选择配送方式弹窗-->
            <div class="shipping-method">
                <span class="ship-text">配送方式</span>
                <div class="delivery">
                    <p class="delivery-method">快递</p>
                    <p class="delivery-method">货到付款</p>
                </div>
            </div>
        </div>

        <!--商品详情-->
        <div class="details-of-goods">
            <p class="goods-text">商品详情</p>
            <div class="goods-pic">
                {$goodsdetail['info']|htmlspecialchars_decode}
            </div>
        </div>

        <!--底部加入购物车-->
        <div class="footer-car">
            <a class="shopping-trolley" href="{:U('GoodShopcart/shopcart')}">
                <img src="{:C('__STATIC__')}{$theme}/Static/img/shopping-trolley.png"/>

                <span>购物车</span>
            </a>
            <span class="join-trolley">加入购物车</span>
            <span class="purchase-now">立即购买</span>
        </div>
    </div>

    <!--添加收货地址-->
    <div class="new-address">
        <div id="headera">
            <div class="header">
                <h1 class="tit">请先添加地址</h1>
                <p class="goback">
                    <a class="gobody">返回</a>
                </p>
            </div>
        </div>
        <div class="tjxdz-a">
            <div class="tjxdz-a1">
                <span>收货人：</span>
                <input type="text" id="s_user"/>
            </div>
            <div class="tjxdz-a1">
                <span>联系电话：</span>
                <input type="text" id="s_mobile" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>
            <div class="tjxdz-a1">
                <span>所在地区：</span>
                <span class="content-block">请选择</span>
                <div class="content-chose" data-toggle="distpicker">
                    <select id="provice"></select>
                    <select id="city"></select>
                    <select id="area"></select>
                </div>
            </div>
            <div class="tjxdz-a1 tjxdz-a4">
                <textarea placeholder="请填写详细地址" id="s_area"></textarea>
            </div>
            <div class="person-form"><span id="add_btn">添加</span></div>
        </div>
    </div>
    </form>
</block>

<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/swiper.css"/>
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/weChat_system.css"/>
</block>
<block name="JS">
    <script src="{:C('__STATIC__')}{$theme}/Static/js/swiper.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.data.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/main.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/layload.js"></script>
    <script type="text/javascript">
        $(function() {
            function get_spec2() {
                //拼接规格和规格的值
                var attr_val = '';
                var str = '';
                $('input:radio:checked').each(function() {
                    if($(this).hasClass("spec")){
                        attr_val = $(this).parent().find('span').text();
                        str += attr_val + ',';
                    }
                });
                str = str.substr(0, str.length - 1);
                return str;
            }

            //地址添加
            $("#add_btn").click(function () {
                //拼接规格和规格的值
                var s_user = $("#s_user").val();
                var s_mobile = $("#s_mobile").val();
                var provice = $("#provice").val();
                var city = $("#city").val();
                var area = $("#area").val();
                var s_area = $("#s_area").val();
                if(!s_user || !s_mobile || !provice || !city || !area || !s_area){
                    layer.alert('信息填写不完整！', {icon: 2});
                    return false;
                }
                $.ajax({
                    type: 'post',
                    url:"{:U('Setting/address_add')}",
                    data: {
                        tel: s_mobile,
                        get_user: s_user,
                        addre:s_area,
                        provice: provice,
                        city: city,
                        area: area
                    },
                    success: function(msg) {
                        if(msg.status == "success") {
                            layer.msg('添加成功！', {icon: 1 ,time: 1000});
                            setTimeout(function(){
                                location.reload(true);
                            }, 1000);
                        }else if(msg.status == "error"){
                            layer.msg(msg.msg, {icon: 2 ,time: 1000});
                        }
                    }
                });
            });

            //加入购物车
            $(".jiaru").click(function () {
                 var session = $(".visitor").val();
                 if(session == ''){
                     location.href =  "{:U('Login/index', array('shop_id'=>session('url_shop_id')))}";
                 }
//                //拼接规格和规格的值
//                var attr_val = '';
//                var attr_name = '';
//                var str = '';
//                $('input:radio:checked').each(function() {
//                    attr_name = $(this).parent().parent().parent().find('.size-tit').text();
//                    attr_val = $(this).parent().find('span').text();
//                    str += attr_name + ':'+attr_val + ';';
//                });
                var is_agent = $('#is_agent').val();
                if (is_agent == 1) {
                    var status = $('.a_type').val();
                } else {
                    var status = 0;
                }

                //验证每个规格都要选
                $che_len = $('input[type="radio"]:checked').length;
                $spec_len = "{$count_gs}" ;
                $is_agent = "{$is_agent}";
//                //是否为代理，打理则多一个箱件的规格
//                if(parseInt($is_agent) == 1){
//                    $t_spec_len = parseInt($spec_len) +1;
//                }else{
//                    $t_spec_len = parseInt($spec_len);
//                }
                if($che_len != $spec_len){
                    layer.msg("请完整选择规格");return false;
                }

                //规格
                var spec_str = get_spec2();
                $('#good_spec').val(spec_str);

                $.ajax({
                    type: 'post',
                    url:"{:U('GoodShopcart/addcart')}",
                    data: {
                        'good_id': $('#good_id').val(),
                        'num':$('#num').text(),
                        'status': status,
                        'spec_str':spec_str,
                    },
                    success: function(msg) {
                        if(msg == 1) {
                            layer.msg('添加购物车成功！', {icon: 1});
                        }else if(msg == -1){
                            layer.msg("商品信息不存在",{icon:2});
                        }else if(msg == -2){
                            layer.msg("商品数量错误",{icon:2});
                        }else if(msg == -3){
                            layer.msg("商品状态错误",{icon:2});
                        }else if(msg == -4){
                            layer.msg("规格信息错误",{icon:2});
                        }
                    }
                });
            })

            //立即购买提交表单
            $('#lima').click(function() {
                var agent_brand = "{$agent_brand}";
                var self_address = "{$self_address}";
                var is_agent = $('#is_agent').val();
                var session = $(".visitor").val();
                if (is_agent == 1) {
                    var status = $('.a_type').val();
                } else {
                    var status = 0;
                }

                //验证每个规格都要选
                $che_len = $('input:radio:checked').length;
                $spec_len = "{$count_gs}" ;
                $is_agent = "{$is_agent}";
                //是否为代理，打理则多一个箱件的规格
//                if(parseInt($is_agent) == 1){
//                    $t_spec_len = parseInt($spec_len) +1;
//                }else{
//                    $t_spec_len = parseInt($spec_len);
//                }
                if($che_len != $spec_len){
                    layer.msg("请完整选择规格");return false;
                }

                //规格
                var spec_str = get_spec2();
                $('#good_spec').val(spec_str);

                //赋值
                $("#count").val($.trim($('.total_price').text()));
                $("#good_num").val($('#num').text());
                if(session !==""){
                    if(self_address == "none"){
                        $(".new-address").addClass("left-address");
                        $(".left-body").addClass("left-html");
                        return false;
                    }
                }
                $a_type = $('.a_type').val();
//                if(agent_brand == 1 && $a_type != 1 && $a_type != 2 && is_agent==1){
//                    layer.msg("请选择商品参数" ,{time: 1500});return false;
//                }
                $("#add-confirm").submit();
            });

            $(".gobody").click(function () {
                $(".new-address").removeClass("left-address");
                $(".left-body").removeClass("left-html");
            });
            $(".content-block").click(function () {
                $(".content-block").hide();
                $(".content-chose").show();
            })

            //商品数量的增加
            $('.plus').click(function() {

                $a_type = $('.a_type').val();
//                var is_agent = $('#is_agent').val();
//                if($a_type != 1 && $a_type != 2 && is_agent==1){
//                    layer.msg("请选择商品参数" ,{time: 1500});return false;
//                }
                var num = $(this).parent().find('.num').text();
                num++;
                $(this).parent().find('.num').text(num);
                sum();
            });

            //商品数量的减少
            $('.reduce').click(function() {

                $a_type = $('.a_type').val();
//                var is_agent = $('#is_agent').val();
//                if($a_type != 1 && $a_type != 2 && is_agent == 1){
//                    layer.msg("请选择商品参数" ,{time: 1500});return false;
//                }
                var num = $(this).parent().find('.num').text();
                if(num >1) num--;
                $(this).parent().find('.num').text(num);
                sum();
            });

//            //单件或整箱的切换
//            $("input[name='good_type']").click(function() {
//                sum();
//                var stock = $(this).parent().find('span').attr('stock');
//                $('#stock').text(stock);
//                var a_type = $(this).attr('for');
//                $('.a_type').attr('value',a_type);
//            });

            //商品价格的计算
            function sum() {
                var is_agent = $('#is_agent').val();
                if (is_agent == 1) {
                    var per_price = $(".dan-price").text();
                } else {
                    var per_price = $('#price').text();
                }

                var num = $('#num').text();

                var total = per_price*num;
                $('.total_price').text(total);
            }

        });
        var swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            spaceBetween: 30,
            centeredSlides: true,
            autoplay: 4000,
            loop: true,
            effect: 'slide',
            autoplayDisableOnInteraction: false,
            lazyLoading : true
        });
    </script>
    <script src="{:C('__STATIC__')}{$theme}/Static/js/details.js"></script>
</block>